package private1;

public class Car1 {
    private String name;//车的名称
    private  int width;//车的宽度
    private  int height;//高度
    private  int length;//长度
    private double x;//当前位置的x的坐标
    private double y;//当前位置的y的坐标
    private double fuel;//剩余燃料
    private Day purchaseDay;//购买日期，类类型字段

    //以上为字段

    //接下来就是构造函数
   public Car1(String name,int width,int height,int length,double fuel,Day purchaseDay){//将形参的值赋给字段
        this.name=name; this.width=width;this.height=height; this.length=length;this.fuel=fuel;//启动他们自身的实例的引用就是this
        x=y=0.0;
        this.purchaseDay=new Day(purchaseDay);
    }

    //接下来是方法
    protected double getX(){return x;}//获取当前位置的x的坐标
    protected double getY(){return y;}//获取当前位置的y的坐标
    protected double getFuel(){return fuel;}//获取剩余燃料
    protected  Day getPurchaseDay(){
            return new Day(purchaseDay);//获取购买日期
    }


    //1.显示车的形状
   protected void putSpec(){
        System.out.println("名称："+name);
        System.out.println("车宽："+width);
        System.out.println("车长："+length);
        System.out.println("车高："+height);
    }
    //2.向x方向移动dx,向y方向移动dy
    protected boolean move(double dx,double dy){
        double dist=Math.sqrt(dx*dx+dy*dy);//移动距离
        if (dist>fuel)
        return false;
        else
        {
            fuel-=dist;
            x+=dx;
            y+=dy;
            return true;
        }
    }

}
